<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :advOptions="[]"
      :dictMap="dictMap"
      :formOptions="formOptions"
      :outputQueryParams="queryParams"
      :queryParams="queryParams"
      :defaultEventKey="defaultEventKey"
      :labelWidth="80"
    ></Ht-search-form>

    <!--    <div class="page-label-block">-->
    <!--      <span class="color-block">|</span>-->
    <!--      <span class="page-label-name">-->
    <!--      租户管理-->
    <!--      </span>-->
    <!--    </div>-->

    <ht-table
      :defaultEventKey="defaultEventKey"
      ref="dataTable"
      :dictMap="dictMap"
      :multi-select="false"
      :opButtonList="opButtonList"
      :queryParams="queryParams"
      :reqConfig="regConfig"
      :showSerialNumber="false"
      :tableBindColumns="tableBindColumns"
    >
      <template v-slot:operate>
        <el-table-column
          align="left"
          fixed="right"
          label="操作"
          width="50"
        >
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  }
                }
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog :close-on-click-modal="false" :title="title" center  :visible.sync="open" v-if="open"  append-to-body width="1024px">


      <el-form ref="detailForm"  :model="detailForm" :rules="rules" label-width="120px" >
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易流水号" prop="id">
              <el-input v-model="detailForm.id" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="工作日期" prop="workdate">
              <el-date-picker v-model="detailForm.workdate" style="width: 100%;" type="date" value-format="yyyyMMdd" :disabled="true"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="CPG日期" prop="vdate">
              <el-date-picker v-model="detailForm.vdate" style="width: 100%;" type="date" value-format="yyyyMMdd" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="报文类型" prop="pkgNo">
              <el-select style="width: 100%;"
                         v-model="detailForm.pkgNo===null||detailForm.pkgNo===undefined?'':detailForm.pkgNo+'-'+detailForm.pkgNoDesc"
                         placeholder="报文类型" :disabled="true"
              >

              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="业务类型" prop="oriBizType">
              <el-select style="width: 100%;"
                         v-model="detailForm.bizType===null||detailForm.bizType===undefined?'':detailForm.bizType+'-'+detailForm.bizTypeDesc"
                         placeholder="业务类型" :disabled="true"
              >

              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="业务种类" prop="业务种类" v-if="this.detailForm.pkgNo==='ccms.312.001.01'">
              <el-select style="width: 100%;"
                         v-model="detailForm.bizCtgy===null||detailForm.bizCtgy===undefined?'':detailForm.bizCtgy+'-'+detailForm.bizCtgyDesc"
                         placeholder="业务种类" :disabled="true"
              >

              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="信息标题" prop="msgTitle">
              <el-input v-model="detailForm.msgTitle" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="信息内容" prop="msgContent">
              <el-input type="textarea" v-model="detailForm.msgContent" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="附件长度" prop="attchmtLength">
              <el-input v-model="detailForm.attchmtLength" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="附件名称" prop="attchmtName">
              <el-input v-model="detailForm.attchmtName" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="接收方" prop="indirectRecver">
              <el-input v-model="detailForm.indirectRecver" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接收方名称" prop="recvername">
              <el-input v-model="detailForm.recvername" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input type="textarea" v-model="detailForm.remarks" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="录入操作员" prop="mdTlrno">
              <el-input v-model="detailForm.mdTlrno" :disabled="true"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="录入时间" prop="mdTime">
              <el-date-picker style="width: 100%;" v-model="detailForm.mdTime" value-format="yyyyMMddHHmmss"
                              type="datetime" :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="审核附言" prop="audRemarks">
              <el-input type="textarea" v-model="detailForm.audRemarks" maxlength="128" show-word-limit/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-card class="form-card txnInfo-card" v-if="this.detailForm.bizType==='M505'&&this.detailForm.bizCtgy==='06814'">
          <div slot="header" class="label-header-msg">
            <span>存量协议信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="地域标识" prop="regionid">
                <el-select style="width: 100%;" v-model="detailForm.regionid" placeholder="地域标识" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.RegionId"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户标识" prop="cstmrId">
                <el-input v-model="detailForm.cstmrId" :disabled="true"/>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="客户名称" prop="cstmrNm">
                <el-input v-model="detailForm.cstmrNm" :disabled="true"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="协议号" prop="ctrctId">
                <el-input v-model="detailForm.ctrctId" :disabled="true"/>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="协议状态" prop="ctrctSts">
                <el-select style="width: 100%;" v-model="detailForm.ctrctSts" placeholder="协议状态" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.CTRCTSTS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="NPC拒绝信息" prop="remarks2">
                <el-input type="textarea" v-model="detailForm.remarks2" :disabled="true"/>
              </el-form-item>
            </el-col>
          </el-row>

        </el-card>


      </el-form>


      <div slot="footer" align="center" class="dialog-footer">
        <el-button type="primary" @click="approve">审 核</el-button>
        <el-button type="primary" @click="reject">拒 绝</el-button>
        <el-button type="primary" @click="downloadFile(detailForm.attchmtContent,detailForm.attchmtName)">下 载</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>



  </div>
</template>

<script>
import {
  apiUrlConfigApproveQuery,
  generalInformationApproveApprove,
  generalInformationApproveDetail, generalInformationApproveDownload,
  generalInformationApproveReject

} from '@/api/cnaps/ccms/310'
import { listPageMixin } from '@/libs/listPageMixin'
import HtAmountInput from "@/views/components/HtAmountInput";
import { baseUrlConfig, downloadfile } from "@/api/authority_app/base";
export default {
  name: "GeneralInformationApprove",
  mixins: [listPageMixin],
  components: {HtAmountInput},
  data() {
    return {
      defaultEventKey:"defaultEventKey",
      // 查询参数
      queryParams: {
        id:undefined
      },
      selectchange:[],
      queryDetailParams: {

      },
      entryDetailForm:{
        pkgNo:undefined
      },

      // 搜索
      formOptions: [],
      //
      searchFormDictList: ["PKG_310_312","CTRCTSTS","RegionId"],
      // 列信息
      regConfig: apiUrlConfigApproveQuery,


      rules:{

      },

      tableBindColumns: [
        { prop: 'coreId',   label: '交易流水号',width:180},
        { prop: 'workdate',   label: '工作日期', type:'date',width:120},
        { prop: 'vdate',   label: 'CPG日期', type:'date',width:120},
        { prop: 'msgtype',   label: '报文类型', dictCode : 'PKG_310_312' ,width:240},
        { prop: 'bizType',   label: '业务类型', formatter(row, text, index) {
            return row['bizType'] + '-' + row['bizTypeDesc']
          },width:240},
        { prop: 'bizCtgy',   label: '业务种类', formatter(row, text, index) {
            return row['bizCtgy'] + '-' + row['bizCtgyDesc']
          },width:240},
        { prop: 'msgTitle',   label: '信息标题',width:120},
        { prop: 'attchmtLength',   label: '附件长度',width:120},
        { prop: 'mdTlrno',   label: '录入操作员',width:120},
        { prop: 'mdTime',   label: '录入时间', type:'date',width:180},
      ],


      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      openDetail: false,
      // 表单参数
      detailForm: {
        pkgNo:undefined,
        pkgNoDesc:undefined
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索




      {
        type: "input",
        prop: "idSeqNo",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate1",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },


      {
        type: "dict",
        dict: "PKG_310_312",
        prop: "mestype",
        defaultAttr: {
          size: "small",
          label: "报文类型",
          placeholder: "请输入报文类型",
        },
      },

    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();

  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs.dataTable.doQuery(true);
    },

    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;


    },



    /** 详情按钮操作 */
    handleDetail(row) {

      generalInformationApproveDetail(row).then(response => {
        this.title="通用信息审核明细"
        if(response.result.data){
          this.detailForm = response.result.data;
        }


        if(response.result.data2){
          this.$set(this.detailForm,"cstmrId",response.result.data2.cstmrId)
          this.$set(this.detailForm,"cstmrNm",response.result.data2.cstmrNm)
          this.$set(this.detailForm,"ctrctId",response.result.data2.ctrctId)
          this.$set(this.detailForm,"ctrctSts",response.result.data2.ctrctSts)
          this.$set(this.detailForm,"regionid",response.result.data2.regionid)
          this.$set(this.detailForm,"remarks2",response.result.data2.remarks)
        }
        this.open = true;
      })
    },


    //审核通过按钮
    approve(){
      this.$refs["detailForm"].validate(valid => {
        if (valid) {
          generalInformationApproveApprove(this.detailForm).then(response => {
            this.msgSuccess("审核通过");
            this.open = false;
          })

        }
      })
    },
    //审核拒绝按钮
    reject(){
      this.$refs["detailForm"].validate(valid => {
        if (valid) {
          generalInformationApproveReject(this.detailForm).then(response => {
            this.msgSuccess("审核拒绝");
            this.open = false;
          })
        }
      })
    },

    //下载按钮
    downloadFile(fileId,fileName) {
      if (fileId !== undefined && fileId !== "") {
        downloadfile(`${baseUrlConfig.downloadFile}`, fileId).then((response) => {
          let type = fileName.split(".")[1];
          let blob = new Blob([response.data], {type: type});
          let objectUrl = URL.createObjectURL(blob);
          const link = document.createElement("a"); // 创建a标签
          link.href = objectUrl;
          // const fileNameSplit = response.headers['content-disposition'].split('=')
          // const fileName = decodeURI(fileNameSplit[fileNameSplit.length - 1]) // 跟后端约定好最后一个值为fileName字段
          link.download = fileName; // 自定义文件名

          link.click(); // 下载文件
          URL.revokeObjectURL(objectUrl); // 释放内存
        });
      } else {
        this.msgError("下载文件不存在");
      }
    },
  }
};
</script>
